package com.guoxue.action.front;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.guoxue.domain.CoinsVo;
import com.guoxue.domain.GiveAwayRecordVo;
import com.guoxue.domain.InventoryVo;
import com.guoxue.domain.OrderVo;
import com.guoxue.domain.PropertyConfigVo;
import com.guoxue.domain.ShopConfigVo;
import com.guoxue.domain.TapesShareVo;
import com.guoxue.domain.UserCoinsVo;
import com.guoxue.domain.UserVo;
import com.guoxue.model.GiftList;
import com.guoxue.model.GiveAwayGiftList;
import com.guoxue.model.Inventory;
import com.guoxue.model.RedisRecentUser;
import com.guoxue.model.ShopConfig;
import com.guoxue.service.ICoinsService;
import com.guoxue.service.IGiftListService;
import com.guoxue.service.IGiveAwayRecordService;
import com.guoxue.service.IInventoryService;
import com.guoxue.service.IOrderService;
import com.guoxue.service.IPropertyConfigService;
import com.guoxue.service.IShopConfigService;
import com.guoxue.service.ITapesShareService;
import com.guoxue.service.IUserCoinsService;
import com.guoxue.service.IUserService;
import com.guoxue.util.LoggerUtil;
import com.guoxue.util.OSSUtil;
import com.guoxue.util.OtherUtils;
import com.guoxue.util.RedisUtil;

import redis.clients.jedis.Jedis;

@Controller
@RequestMapping(value="/shop")
public class ShopAction extends BaseAction{
	
	@Resource
	private ICoinsService coinsService;
	@Resource
	private IPropertyConfigService propertyConfigService;
	@Resource
	private IOrderService orderService;
	@Resource
	private IUserCoinsService userCoinsService;
	@Resource
	private IInventoryService  inventoryService;
	@Resource
	private IGiveAwayRecordService  giveAwayRecordService;
	@Resource
	private IUserService  userService;
	@Resource
	private IGiftListService  iGiftListService;
	@Resource
	private ITapesShareService tapesShareService;
	@Resource
	private OSSUtil oss;
	@Resource
	private IShopConfigService shopConfigService;
	/**
	 * 获取用户背包里的商品信息
	 * @param req
	 * @param resp
	 * @param uid 用户id
	 * @return 
	 */
	@ResponseBody
	@RequestMapping(value="/getInventoryList")
	public  JSON getInventoryList(HttpServletRequest req, HttpServletResponse resp,Integer uid){
		try {
			if(null == uid){
				return Message(ERROR, "未提交用户id", null);
			}
			List<InventoryVo> inventoryVoList = inventoryService.getInventoryList(uid);
			List<Inventory>  inventoArryList = new ArrayList<>();
			for(InventoryVo inventoryVo : inventoryVoList){
				PropertyConfigVo propertyConfig = propertyConfigService.getPropertyConfigById(inventoryVo.getGoodsId());
				propertyConfig.setPropIcon(isEmpty(propertyConfig.getPropIcon())?null:oss.getUrl(bucket,propertyConfig.getPropIcon(),  new Date(new Date().getTime() + 3600 * 1000 * 12)));
				Inventory inventory = new Inventory(inventoryVo,propertyConfig);
				ShopConfigVo shopConfig = shopConfigService.getShopConfig(propertyConfig.getPropId());
				inventory.setPrice(shopConfig.getPrice());
				if(inventory.getProCount() > 0){
					inventoArryList.add(inventory);
				}
			}
			return Message(SUCCESS, "获取数据成功", inventoArryList);
		} catch (Exception e) {
			return LoggerUtil.logInfo(e, "获取数据失败");
		}
	}
	
	/**
	 * 获取用户背包里的某个类型的所有商品信息
	 * @param req
	 * @param resp
	 * @param uid 用户id
	 * @param typeId 商品类型id
	 * @return 
	 */
	@ResponseBody
	@RequestMapping(value="/getInventoryGoodsTypeList")
	public  JSON getInventoryGoodsTypeList(HttpServletRequest req, HttpServletResponse resp,Integer uid,Integer typeId){
		try {
			if(null == uid){
				return Message(ERROR, "未提交用户id", null);
			}
			if(null == typeId){
				return Message(ERROR, "未提交商品类型id", null);
			}
			List<InventoryVo> inventoryVoList = inventoryService.getInventoryGoodsTypeList(uid,typeId);
			List<Inventory>  inventoArryList = new ArrayList<>();
			for(InventoryVo inventoryVo : inventoryVoList){
				PropertyConfigVo propertyConfig = propertyConfigService.getPropertyConfigById(inventoryVo.getGoodsId());
				propertyConfig.setPropIcon(isEmpty(propertyConfig.getPropIcon())?null:oss.getUrl(bucket,propertyConfig.getPropIcon(),  new Date(new Date().getTime() + 3600 * 1000 * 12)));
				Inventory inventory = new Inventory(inventoryVo,propertyConfig);
				ShopConfigVo shopConfig = shopConfigService.getShopConfig(propertyConfig.getPropId());
				inventory.setPrice(shopConfig.getPrice());
				if(inventory.getProCount() > 0){
					inventoArryList.add(inventory);
				}
			}
			
			return Message(SUCCESS, "获取数据成功", inventoArryList);
		} catch (Exception e) {
			return LoggerUtil.logInfo(e, "获取数据失败");
		}
	}
	
	/**
	 * 赠送礼物
	 * @param req
	 * @param resp
	 * @param uid 
	 * 			用户id
	 * @param goodsId 
	 * 			商品id
	 * @param giveUid 
	 * 			赠送人id
	 * @param count 
	 * 			赠送数量
	 * @param tapesId 
	 * 			作品id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/giveAway")
	public JSON giveAway(HttpServletRequest req, HttpServletResponse resp,
			Integer uid,Integer goodsId,Integer giveUid,Integer count,Integer tapesId){
		try {
			if(null == uid){
				return Message(ERROR, "未提交用户id", null);
			}
			if(null == goodsId){
				return Message(ERROR, "未提交商品id", null);
			}
			if(null == giveUid){
				return Message(ERROR, "未提交赠送人id", null);
			}
			if(null == count){
				return Message(ERROR, "未提交赠送数量", null);
			}
			if(count <= 0){
				return Message(ERROR, "赠送数量不能小于等于0", null);
			}
			if(null == tapesId){
				return Message(ERROR, "未提交作品id", null);
			}
			InventoryVo inventoryVo = inventoryService.getInventoryByUidAndGoodsId(uid,goodsId);
			if(null != inventoryVo){
				if(count > inventoryVo.getProCount()){
					return Message(ERROR, "您当前的商品数量小于赠送的数量", null);
				}else{
					PropertyConfigVo propertyConfig = propertyConfigService.getPropertyConfigById(goodsId);
					Integer proCount = (inventoryVo.getProCount() - count);
					inventoryVo.setProCount(proCount);
					inventoryService.saveInventory(inventoryVo);
					//更新用户人气
					TapesShareVo tapesShare = null;
					tapesShare = tapesShareService.getTapesShareByTid(tapesId, 0);
					if (tapesShare==null){
						tapesShare = new TapesShareVo();
						tapesShare.setTotalGifts(Integer.parseInt(propertyConfig.getParameter1())*count);
						tapesShare.setWeeklyGifts(Integer.parseInt(propertyConfig.getParameter1())*count);
						tapesShare.setWeeklyTotalGifts(Integer.parseInt(propertyConfig.getParameter1())*count);
					} else {
						tapesShare.setTotalGifts(tapesShare.getTotalGifts()+Integer.parseInt(propertyConfig.getParameter1())*count);
						tapesShare.setWeeklyGifts(tapesShare.getWeeklyGifts()+Integer.parseInt(propertyConfig.getParameter1())*count);
						tapesShare.setWeeklyTotalGifts(tapesShare.getWeeklyTotalGifts()+Integer.parseInt(propertyConfig.getParameter1())*count);
					}
					GiveAwayRecordVo  giveAwayRecordVo = new GiveAwayRecordVo();
					giveAwayRecordVo.setTotal(count);
					giveAwayRecordVo.setGiveTime(OtherUtils.getCurrentDate().toString());
					giveAwayRecordVo.setGiveUid(uid);
					giveAwayRecordVo.setGoodsId(goodsId);
					ShopConfigVo shopConfig = shopConfigService.getShopConfig(goodsId);
					Integer popularityValue = shopConfig.getPrice()*count;
					giveAwayRecordVo.setPopularityValue(popularityValue);
					giveAwayRecordVo.setTapesId(tapesId);
					giveAwayRecordVo.setUid(giveUid);
					giveAwayRecordService.saveGiveAwayRecord(giveAwayRecordVo);
					tapesShareService.saveTapesShare(tapesShare);
					return Message(SUCCESS, "赠送成功", null);
				}
			}else{
				return Message(ERROR, "您尚未拥有改商品", null);
			}
		} catch (Exception e) {
			return LoggerUtil.logInfo(e, "赠送失败");
		}
	}
	
	/**
	 * 赠送礼物榜单
	 * @param req
	 * @param resp
	 * @param userId 用户id
	 * @param tapesId 作品id
	 * @param start 从第几条数据开始取
	 * @param total 取多少条数据
	 * @param flag 是否取自己的数据
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/giveAwayList")
	public  JSON giveAwayList(HttpServletRequest req, HttpServletResponse resp,
			Integer userId,Integer tapesId,Integer start ,Integer total,Integer flag,String date){
		try {
			if(null == userId){
				return Message(ERROR, "未提交用户id", null);
			}
			if(null == tapesId){
				return Message(ERROR, "未提交作品id", null);
			}
			if(null == start){
				return Message(ERROR, "未提交从第几条数据开始取", null);
			}
			if(null == total){
				return Message(ERROR, "未提交取多少条数据", null);
			}
			if (isEmpty(date)){
				return Message(ERROR, "未提交时间", null);
			}
			JSONObject json =  new JSONObject();
			List<GiveAwayGiftList> GiveAwayGiftList = new ArrayList<>();
			if(null != flag && flag == 1){
				if(start == 0){
					GiveAwayGiftList giveAwayGiftList = iGiftListService.getGiveAwayGift(userId,tapesId);
					if(null == giveAwayGiftList){
						UserVo userVo = userService.getUserByKey(userId);
						GiveAwayGiftList g = new GiveAwayGiftList();
						g.setGiveUid(userVo.getId());
						g.setGiveUidImgUrl(isEmpty(userVo.getImgUrl())?null:oss.getUrl(bucket, userVo.getImgUrl(),  new Date(new Date().getTime() + 3600 * 1000 * 12)));
						g.setGiveUidName(userVo.getNickName());
						g.setToatlNumber("0");
						GiveAwayGiftList.add(g);
					}else{
						GiftList GiftList = iGiftListService.getGift(userId, tapesId);
						if(null != GiftList){
							giveAwayGiftList.setToatlNumber(GiftList.getTotalNumber());
							giveAwayGiftList.setGoodsImg(isEmpty(GiftList.getPropIcon())?null:oss.getUrl(bucket, GiftList.getPropIcon(),  new Date(new Date().getTime() + 3600 * 1000 * 12)));
						}else{
							giveAwayGiftList.setToatlNumber("0");
							giveAwayGiftList.setGoodsImg(null);
						}
						String url = giveAwayGiftList.getGiveUidImgUrl();
						giveAwayGiftList.setGiveUidImgUrl(isEmpty(url)?null:oss.getUrl(bucket, url,  new Date(new Date().getTime() + 3600 * 1000 * 12)));
						GiveAwayGiftList.add(giveAwayGiftList);
					}
				}
			}
			List<GiveAwayGiftList> gGiveAwayGiftList = new ArrayList<GiveAwayGiftList>();
			if (date.equals("0")){
				gGiveAwayGiftList = iGiftListService.getGiveAwayGiftList(userId, tapesId, start, total);
			} else {
				gGiveAwayGiftList = iGiftListService.getGiveAwayGiftList(userId, tapesId, start, total,date);
			}
			if (!date.equals("0")){
				if(gGiveAwayGiftList==null||gGiveAwayGiftList.isEmpty()){
					return Message(ERROR, "没有更多了··", null);
				}
			}
			for(int i=0;i< gGiveAwayGiftList.size();i++){
				GiftList GiftList = iGiftListService.getGift(gGiveAwayGiftList.get(i).getGiveUid(), tapesId);
				if(null != GiftList){
					if(Integer.valueOf(GiftList.getTotalNumber()) > 0){
						gGiveAwayGiftList.get(i).setToatlNumber(GiftList.getTotalNumber());
						String url = gGiveAwayGiftList.get(i).getGiveUidImgUrl();
						gGiveAwayGiftList.get(i).setGiveUidImgUrl(isEmpty(url)?null:oss.getUrl(bucket, url,  new Date(new Date().getTime() + 3600 * 1000 * 12)));
						gGiveAwayGiftList.get(i).setGoodsImg(isEmpty(GiftList.getPropIcon())?null:oss.getUrl(bucket, GiftList.getPropIcon(),  new Date(new Date().getTime() + 3600 * 1000 * 12)));
					}else{
						gGiveAwayGiftList.remove(i);
					}
				}
			}
			if(gGiveAwayGiftList.size() >= 2){
				Collections.sort(gGiveAwayGiftList,new Comparator<GiveAwayGiftList>(){
					@Override
					public int compare(GiveAwayGiftList o1, GiveAwayGiftList o2) {
						Integer od = Integer.valueOf(o1.getTotalPopularityValue());
						Integer od2 = Integer.valueOf(o2.getTotalPopularityValue());
						if ( od < od2) {
							return 1;
						}
						return -1;
					}
				});
			}
			GiveAwayGiftList.addAll(gGiveAwayGiftList);
			JSONArray array = new JSONArray();
			//List<GiveAwayVo> giveAwayList = giveAwayService.getGiveAwayList(uid,tapesId,start,total);//贡献榜单
		/*	List<GiveAwayRecordVo> giveAwayRecordList = giveAwayRecordService.getGiveAwayRecordList(uid,tapesId,start,total);
			List<GiveAwayGiftList> giveAwayGift = new ArrayList<GiveAwayGiftList>();
			if(null != giveAwayRecordList){
				List<Integer> list = new ArrayList<>();
				for(GiveAwayRecordVo g :giveAwayRecordList){
					if(!list.contains(g.getGiveUid())) {  
			            list.add(g.getGiveUid());  
			        } 
				}
				for(int i=0;i<list.size();i++){
					GiveAwayGiftList  giveAwayGiftList = new GiveAwayGiftList();
					UserVo userVo = userService.getUserByKey(list.get(i));
					Long number = giveAwayRecordService.getGiveAwayRecordPopularityValueTotal(list.get(i));
					Map<String,String> List = giveAwayRecordService.getGiveAwayRecordGoodsTotal(list.get(i)); 
					if(null != List){
						giveAwayGiftList.setToatlNumber(List.get("popularityValue"));
						Integer goodsId = Integer.valueOf(List.get("goodsId"));
						giveAwayGiftList.setGoodsId(goodsId);
						PropertyConfigVo  propertyConfigVo = propertyConfigService.getPropertyConfigById(goodsId);
						giveAwayGiftList.setGoodsImg(propertyConfigVo.getPropIcon());
					}
					giveAwayGiftList.setGiveUid(userVo.getId());
					giveAwayGiftList.setGiveUidImgUrl(userVo.getImgUrl());
					giveAwayGiftList.setGiveUidName(userVo.getNickName());
					giveAwayGiftList.setTotalPopularityValue(number.toString());
					giveAwayGift.add(giveAwayGiftList);
				}
			}
			if(giveAwayGift.size() >= 2){
				Collections.sort(giveAwayGift,new Comparator<GiveAwayGiftList>(){
					@Override
					public int compare(GiveAwayGiftList o1, GiveAwayGiftList o2) {
						Integer od = Integer.valueOf(o1.getTotalPopularityValue());
						Integer od2 = Integer.valueOf(o2.getTotalPopularityValue());
						if ( od < od2) {
							return 1;
						}
						return -1;
					}
				});
			}*/
			/*Jedis jedis = RedisUtil.getJedis();
			//获取最近听众
			List<RedisRecentUser> redisRecentUserList = (List<RedisRecentUser>) RedisUtil.unserialize(jedis.get((tapesId + "L").getBytes()));
			jedis.close();
			if(null != redisRecentUserList){
				if(redisRecentUserList.size() >= 12){
					array.addAll(redisRecentUserList.subList(0, 12));
				}else{
					array.addAll(redisRecentUserList);
				}
			}*/
			if(GiveAwayGiftList.size() > 0){
				json.put("giveAwayList", GiveAwayGiftList);
			}else{
				json.put("giveAwayList", new JSONArray());
			}
			json.put("recentUser", array);
			json.put("time", OtherUtils.getCurrentDate());
			return Message(SUCCESS, "获取赠送礼物榜成功", json);
		} catch (Exception e) {
			return LoggerUtil.logInfo(e, "获取赠送礼物榜失败");
		}
	}
	
	/**
	 * 某人赠送了多少礼物
	 * @param req
	 * @param resp
	 * @param giveUid 
	 * 			赠送用户id
	 * @param tapesId  作品id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/giveAwayUidList")
	public  JSON giveAwayUidList(HttpServletRequest req, HttpServletResponse resp,Integer giveUid,Integer tapesId){
		try {
			if(null == giveUid){
				return Message(ERROR, "未提交赠送用户id", null);
			}
			if(null == tapesId){
				return Message(ERROR, "未提交作品id", null);
			}
			List<GiftList> Gift = iGiftListService.getGiftList(giveUid,tapesId);
			for(GiftList g:Gift){
				g.setPropIcon(isEmpty(g.getPropIcon())?null:oss.getUrl(bucket, g.getPropIcon(),  new Date(new Date().getTime() + 3600 * 1000 * 12)));
			}
			return Message(SUCCESS, "获取个人赠送礼物列表成功", Gift);
		} catch (Exception e) {
			return LoggerUtil.logInfo(e, "获取个人赠送礼物列表失败");
		}
	}
	/*
	 * @ResponseBody
	 * @RequestMapping(value="/getCoins") public JSON
	 * getCoins(HttpServletRequest req, HttpServletResponse resp,Integer
	 * coinsId){ try { if(null == coinsId){ return Message(ERROR,
	 * "未提交金币id", null); } CoinsVo coins =
	 * coinsService.getCoinsById(coinsId); return Message(SUCCESS,
	 * "获取数据成功", coins); } catch (Exception e) { return
	 * LoggerUtil.logInfo(e, "获取数据失败"); } }
	 */
	
	/**
	 * 获取用户购买所有商品订单信息
	 * @param req
	 * @param resp
	 * @param uid 用户id
	 * @return
	 */
	/*
	 * @ResponseBody
	 * 
	 * @RequestMapping(value="/getOrderList") public JSON
	 * getOrderList(HttpServletRequest req, HttpServletResponse resp,Integer
	 * uid){ try { if(null == uid){ return Message(ERROR, "未提交用户id", null); }
	 * List<OrderVo> orderVoList = orderService.getOrderList(uid); return
	 * Message(SUCCESS, "获取数据成功", orderVoList); } catch (Exception e) { return
	 * LoggerUtil.logInfo(e, "获取数据失败"); } }
	 */
	
	/**
	 * 获取用户单个商品订单详情
	 * @param req
	 * @param resp
	 * @param uid 用户id
	 * @return
	 */
	/*
	 * @ResponseBody
	 * 
	 * @RequestMapping(value="/getOrder") public JSON
	 * getOrder(HttpServletRequest req, HttpServletResponse resp,Integer
	 * orderId,Integer uid){ try { if(null == uid){ return Message(ERROR,
	 * "未提交用户id", null); } OrderVo orderVo = orderService.getOrder(orderId,uid);
	 * return Message(SUCCESS, "获取数据成功", orderVo); } catch (Exception e) {
	 * return LoggerUtil.logInfo(e, "获取数据失败"); } }
	 */
	/**
	 * 购买商品并下单
	 * @param req
	 * @param resp
	 * @param propId 商品id
	 * @param count 商品数量
	 * @param uid 用户id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/buyShopGoods")
	public  JSON buyShopGoods(HttpServletRequest req, HttpServletResponse resp,Integer propId,Integer count,Integer uid){
		try {
			if(null == uid){
				return Message(ERROR, "未提交用户id", null);
			}
			if (propId==null){
				return Message(ERROR, "未提交商品id", null);
			}
			if (count==null || count < 0){
				return Message(ERROR, "未提交商品数量或者数量小于等于0", null);
			}
			UserCoinsVo userCoins = userCoinsService.getUserCoinsById(uid);	
			Integer coinsNumber = userCoins.getCoinsNumber();
			if(coinsNumber <= 0){
				return Message(ERROR, "您当前账号没有金币,请购买金币。", null);
			}
			ShopConfigVo shopConfig = shopConfigService.getShopConfig(propId);
			if(count > shopConfig.getBuyLimit()){
				return Message(ERROR, "您一次性购买不能超过限制的数量", null);
			}
			PropertyConfigVo propertyConfigVo  = propertyConfigService.getPropertyConfigById(propId);
			Integer price = (shopConfig.getPrice()*count);
			String outOfTime = propertyConfigVo.getParameter2();
			Integer IsOverlay = propertyConfigVo.getIsOverlay();
			Integer OverlayCount = propertyConfigVo.getOverlayCount();
			if(coinsNumber < price ){
				return Message(ERROR, "您当前的金币数量不足,请购买金币。", null);
			}
			OrderVo order = new OrderVo();
			order.setCount(count);
			order.setGoodsId(propId.toString());
			order.setUid(String.valueOf(uid));
			order.setPayCoins(price);
			order.setCreateTime(OtherUtils.getCurrentDate().toString());
			orderService.saveOrder(order);
			coinsNumber = coinsNumber - price;
			userCoins.setCoinsNumber(coinsNumber);
			userCoinsService.saveUserCoins(userCoins);
			if( IsOverlay == 1 && IsOverlay.equals("1")){//叠加
				InventoryVo inventoryVo =inventoryService.getInventoryByUidAndGoodsId(uid,propId);
				if(null != inventoryVo){//有数据
					Integer countTotal = inventoryVo.getProCount() ;
					if(countTotal == OverlayCount && OverlayCount.equals(countTotal)){//叠加到最高值,重新建立数据
						inventoryVo = new  InventoryVo();
						inventoryVo.setUid(uid);
						inventoryVo.setGoodsId(propId);
						inventoryVo.setCreateTime(OtherUtils.getCurrentDate().toString());
						if(null != outOfTime){
							inventoryVo.setOutOfTime(outOfTime);
						}else{
							inventoryVo.setOutOfTime("0");
						}
						inventoryVo.setProCount(count);
						inventoryVo.setTypeId(Integer.valueOf(propertyConfigVo.getPropType()));
						inventoryService.saveInventory(inventoryVo);
					}else{//叠加未达到最高数量,就数量增加
						Integer proCount = inventoryVo.getProCount()+count;
						inventoryVo.setProCount(proCount);
						inventoryService.saveInventory(inventoryVo);
					}
				}else{//没有数据
					inventoryVo = new  InventoryVo();
					inventoryVo.setUid(uid);
					inventoryVo.setGoodsId(propId);
					inventoryVo.setCreateTime(OtherUtils.getCurrentDate().toString());
					if(null != outOfTime){
						inventoryVo.setOutOfTime(outOfTime);
					}else{
						inventoryVo.setOutOfTime("0");
					}
					inventoryVo.setProCount(count);
					inventoryVo.setTypeId(Integer.valueOf(propertyConfigVo.getPropType()));
					inventoryService.saveInventory(inventoryVo);
				}
			}else{//不能叠加
				InventoryVo inventoryVo =inventoryService.getInventoryByUidAndGoodsId(uid,propId);
				if(null == inventoryVo){//没有数据
					inventoryVo = new  InventoryVo();
					inventoryVo.setUid(uid);
					inventoryVo.setGoodsId(propId);
					inventoryVo.setCreateTime(OtherUtils.getCurrentDate().toString());
					if(null != outOfTime){
						inventoryVo.setOutOfTime(outOfTime);
					}else{
						inventoryVo.setOutOfTime("0");
					}
					inventoryVo.setProCount(count);
					inventoryVo.setTypeId(Integer.valueOf(propertyConfigVo.getPropType()));
					inventoryService.saveInventory(inventoryVo);
				}else{//有数据
					Integer proCount = inventoryVo.getProCount()+count;
					inventoryVo.setProCount(proCount);
					inventoryService.saveInventory(inventoryVo);
				}
			}
			JSONObject josn = new JSONObject();
			josn.put("coinsNumber", userCoins.getCoinsNumber());
			return Message(SUCCESS, "购买商品成功", josn);
		} catch (Exception e) {
			return LoggerUtil.logInfo(e, "购买商品失败");
		}
	}
	

	
}
